package com.hh.flex.key;

import cn.hutool.core.util.ObjectUtil;
import com.hh.common.core.domain.BaseEntity;
import com.hh.common.utils.uuid.IdUtils;
import com.mybatisflex.core.keygen.IKeyGenerator;

/**
 * @author minliuhua
 * @description: 雪花算法
 * @date: 2023/5/28 22:29
 */
public class SnowId implements IKeyGenerator {

    @Override
    public Object generate(Object entity, String keyColumn) {
        BaseEntity baseEntity = (BaseEntity) entity;
        if (ObjectUtil.isNotNull(baseEntity.getId())) {
            return baseEntity.getId();
        }
        return IdUtils.snowflakeId();
    }
}
